<?php

/**
 * Experimental feature - to be activated soon.
 */

Configure::write('AdminAlert.models', array());
App::import('Vendor', 'Cms.EventManager');

class AdminAlert extends AppModel implements EventListener
{
	var $name = 'AdminAlert';
	
	var $useTable = false; // @todo Remove later when needed
	
	var $eventToMessage = array(
		'record_deleted' => ':model_name #:id has been deleted.',
		'record_created' => 'A new :model_name (id #:id) has been added.',
		'record_updated' => ':model_name #:id has been updated.',
	);
	
	function onTrigger($event, $params, $group)
	{
		if($group == 'model')
		{
			if(in_array($params['model_name'], cr('AdminAlert.models')))
			{
				$newAlert = array('AdminAlert' => array(
					'message' => String::insert($this->eventToMessage[$event], Utility::dotNotation($params))
				));
				$this->save($newAlert);
				$this->id = '';			
			}
		}
	}
}

?>